package servlet;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.ClearMachine;
import dao.ClearMachineDao;

public class AddClearServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String id=request.getParameter("lowid");
		String name=request.getParameter("lowname");
		String type=request.getParameter("type");
		String producer=request.getParameter("producer");
		String version=request.getParameter("version");
		String setTime=request.getParameter("settime");
		   DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
		   Date stime = null;
		try {
			stime = df.parse(setTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ClearMachine cm=new ClearMachine();
		cm.setLowid(id);
		cm.setName(name);
		cm.setType(type);
		cm.setProducer(producer);
		cm.setVersion(version);
		cm.setSetTime(stime);
		
		ClearMachineDao cdao=new ClearMachineDao();
		cdao.addClearMachine(cm);
		
		request.getRequestDispatcher("/user/PLCManage.jsp").forward(request, response);
	}

}
